/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.softace.jdbc;

/**
 * An object that holds information about some basic information properties of
 * the designated column in a {@code ResultSet} object.
 *
 * @see JdbcResultSetMetaData
 * @author s1lent_warrior
 */
public class JdbcColumn {

    private final int columnIndex;
    private final String columnName;
    private final String columnAlias;
    private final String columnTitle;
    private final int columnType;
    private final String columnClassName;
    private final String tableName;
    private final String tableAlias;

    JdbcColumn(int columnIndex, String columnName, String columnLabel, String columnTitle,
            int columnType, String columnTypeName, String tableName, String tableAlias) {
        this.columnIndex = columnIndex;
        this.columnName = columnName;
        this.columnAlias = columnLabel;
        this.columnTitle = columnTitle;
        this.columnType = columnType;
        this.columnClassName = columnTypeName;
        this.tableName = tableName;
        this.tableAlias = tableAlias;
    }

    /**
     * Gets the column number of the designated column in a {@code ResultSet}.
     * <br>The column Index starts from 1,2,3....
     *
     * @return the column index
     */
    public int getColumnIndex() {
        return columnIndex;
    }

    /**
     * Retrieves the name of the designated column in a {@code
     * }{@code ResultSet}.
     *
     * @return the column name
     */
    public String getColumnName() {
        return columnName;
    }

    /**
     * Gets the alias of the designated column defined in {@code
     * }{@code AS} clause in a {@code ResultSet}.<br>If no
     * alias is defined, the column name is returned.
     *
     * @return the column alias
     * @see JdbcColumn#getColumnName()
     */
    public String getColumnAlias() {
        return columnAlias;
    }

    /**
     * Gets the column title (i.e: in {@code table_name.column_name} format) of
     * the designated column in a {@code ResultSet}
     *
     * @return column title in {@code table_name.column_name}
     * format
     */
    public String getColumnTitle() {
        return columnTitle;
    }

    /**
     * Retrieves the designated column's SQL type.
     *
     * @return SQL type from java.sql.Types
     * @see java.sql.Types
     */
    public int getColumnType() {
        return columnType;
    }

    /**
     * Returns the fully-qualified name of the Java class for the designated
     * column.
     *
     * @return the fully-qualified name of the class in the Java programming
     * language
     */
    public String getColumnClassName() {
        return columnClassName;
    }

    /**
     * Gets the designated column's table name.
     *
     * @return table name or "" if not applicable
     */
    public String getTableName() {
        return tableName;
    }

    /**
     * Gets the designated column's table alias defined in the {@code AS} clause
     * of a query for the designated column. If no table alias is defined, this
     * method returns the table name for the designated column.
     *
     * @return table alias or table name if no table alias defined
     * @see JdbcColumn#getTableName()
     *
     */
    public String getTableAlias() {
        return tableAlias;
    }

    @Override
    public String toString() {
        return "JdbcColumn{"
                + "columnIndex=" + columnIndex + ", "
                + "columnName=" + columnName + ", "
                + "columnLabel=" + columnAlias + ", "
                + "columnTitle=" + columnTitle + ", "
                + "columnType=" + columnType + ", "
                + "columnTypeName=" + columnClassName + ", "
                + "tableName=" + tableName + ", "
                + "tableAlias=" + tableAlias
                + '}';
    }
}
